package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {
//    @GetMapping("/")
//    public String home() {
//        return "info";
//    }
@PostMapping("/login")
public String login(@RequestParam String username, @RequestParam String password, Model model) {
    if ("admin".equals(username) && "1234".equals(password)) {
        return "info";
    } else {
        model.addAttribute("errorMessage", "用户名或密码错误");
        return "error";
    }
}
    @GetMapping("/login")
    public String login() {
        return "login";
    }
}
